package com.itboye.hutouben.presenter;

import com.itboye.hutouben.bean.OrderBeans;
import com.itboye.hutouben.interfaces.DingDanInterfaces;
import com.itboye.hutouben.responsitory.DingDanResponsitory;
import com.itboye.hutouben.volley.ICompleteListener;
import com.itboye.hutouben.volley.ResultEntity;

import java.util.Observer;

/**
 * 订单
 */

public class DingDanPresenter extends BasePresenter implements DingDanInterfaces<OrderBeans> {
    //订单创建
    public static final String chuangjian_success = DingDanPresenter.class.getName()
            + "_chuangjian_success";
    public static final String chuangjian_fail = DingDanPresenter.class.getName()
            + "_chuangjian_fail";
    //订单创建
    public static final String chuangjian_two_success = DingDanPresenter.class.getName()
            + "_chuangjian_two_success";
    public static final String chuangjian_two_fail = DingDanPresenter.class.getName()
            + "_chuangjian_two_fail";
    //订单分页查询
    public static final String daingdan_query_success = DingDanPresenter.class.getName()
            + "_daingdan_query_success";
    public static final String daingdan_query_fail = DingDanPresenter.class.getName()
            + "_daingdan_query_fail";
    //订单详情
    public static final String daingdan_xiangqing_success = DingDanPresenter.class.getName()
            + "_daingdan_xiangqing_success";
    public static final String daingdan_xiangqing_fail = DingDanPresenter.class.getName()
            + "_daingdan_xiangqing_fail";
    //订单立即购买
    public static final String liji_goumai_success = DingDanPresenter.class.getName()
            + "_liji_goumai_success";
    public static final String liji_goumai_fail = DingDanPresenter.class.getName()
            + "_liji_goumai_fail";
    //订单重新支付
    public static final String chongxin_goumai_success = DingDanPresenter.class.getName()
            + "_chongxin_goumai_success";
    public static final String chongxin_goumai_fail = DingDanPresenter.class.getName()
            + "_chongxin_goumai_fail";
    //微信预支付
    public static final String weixin_pay_success = DingDanPresenter.class.getName()
            + "_weixin_pay_success";
    public static final String weixin_pay_fail = DingDanPresenter.class.getName()
            + "_weixin_pay_fail";
    //余额支付
    public static final String yue_success = DingDanPresenter.class.getName()
            + "_yue_success";
    public static final String yue_fail = DingDanPresenter.class.getName()
            + "_yue_fail";

    //充值（获取充值信息）
    public static final String chongzhi_success = DingDanPresenter.class.getName()
            + "_chongzhi_success";
    public static final String chongzhi_fail = DingDanPresenter.class.getName()
            + "_chongzhi_fail";
    //取消支付
    public static final String quxiao_success = DingDanPresenter.class.getName()
            + "_quxiao_success";
    public static final String quxiao_fail = DingDanPresenter.class.getName()
            + "_quxiao_fail";
    //删除绑定的账号
    public static final String delete_zhanghao_success = DingDanPresenter.class.getName()
            + "_delete_zhanghao_success";
    public static final String delete_zhanghao_fail = DingDanPresenter.class.getName()
            + "_delete_zhanghao_fail";
    //根据卡号查询类型
    public static final String card_type_success = DingDanPresenter.class.getName()
            + "_card_type_success";
    public static final String card_type_fail = DingDanPresenter.class.getName()
            + "_card_type_fail";
    public DingDanPresenter(Observer observer) {
        super(observer);
    }

    /**
     * 订单创建
     * @param uid
     * @param ids           购物车项目id[必须]
     * @param address_id   收货地址id[必须]
     * @param del           删除购物车项标记[可选，默认0 创建订单后不删除购物车项]
     * @param note          备注[可选]
     */
    @Override
    public void generateOrder(String s_id,String uid, String ids, String address_id, String del, String note,String score,String bill_type,String bill_title,String bill_code) {
        DingDanInterfaces<OrderBeans> dingdan = new DingDanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(chuangjian_success);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(chuangjian_fail);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);

                    }
                });
        dingdan.generateOrder(s_id,uid, ids,address_id,del,note,score,bill_type,bill_title,bill_code);
    }
    @Override
    public void generateOrderTwo(String s_id,String uid, String ids, String address_id, String del, String note,String score,String bill_type,String bill_title,String bill_code) {
        DingDanInterfaces<OrderBeans> dingdan = new DingDanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(chuangjian_two_success);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(chuangjian_two_fail);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);

                    }
                });
        dingdan.generateOrderTwo(s_id,uid, ids,address_id,del,note,score,bill_type,bill_title,bill_code);
    }
    /**
     * 订单分页查询
     * @param uid
     * @param keyword       订单关键词（目前和订单包含的商品名称关联）[可选]
     * @param query_status  订单查询状态 [0=>全部,1=>待付款,2=>待发货,3=>待收货,4=>已收货, 7=>已完成 8=>已关闭][可选]
     * @param page_index    页码
     * @param page_size     页大小
     */
    @Override
    public void orderQuery(String s_id,String uid, String keyword, String query_status, String page_index, String page_size) {
        DingDanInterfaces<OrderBeans> dingdan = new DingDanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(daingdan_query_success);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(daingdan_query_fail);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);

                    }
                });
        dingdan.orderQuery(s_id,uid, keyword,query_status,page_index,page_size);
    }

    /**
     * 订单详情
     * @param uid
     * @param order_code
     */
    @Override
    public void orderDetail(String uid, String order_code) {
        DingDanInterfaces<OrderBeans> dingdan = new DingDanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(daingdan_xiangqing_success);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(daingdan_xiangqing_fail);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);

                    }
                });
        dingdan.orderDetail(uid, order_code);
    }

    /**
     * 立即购买
     * @param uid
     * @param sku_pkid      购买的商品的规格id多个逗号分开（注意：不是sku_id）
     * @param count          购买的数量，多个逗号分开（与sku_pkid应该一致）
     * @param address_id    收货地址id[必须]
     * @param note           备注[可选]
     */
    @Override
    public void lijiGouMai(String s_id,String uid, String sku_pkid, String count, String address_id, String note) {
        DingDanInterfaces<OrderBeans> dingdan = new DingDanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(liji_goumai_success);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(liji_goumai_fail);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);

                    }
                });
        dingdan.lijiGouMai(s_id,uid, sku_pkid,count,address_id,note);
    }

    @Override
    public void chongxinGouMai(String s_id,String uid,String order_code) {
        DingDanInterfaces<OrderBeans> dingdan = new DingDanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(chongxin_goumai_success);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(chongxin_goumai_fail);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);

                    }
                });
        dingdan.chongxinGouMai(s_id,uid,order_code);
    }

    @Override
    public void WeiXinPay(String pay_code) {
        DingDanInterfaces<OrderBeans> dingdan = new DingDanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(weixin_pay_success);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(weixin_pay_fail);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);

                    }
                });
        dingdan.WeiXinPay(pay_code);
    }

    @Override
    public void chongZhi(String uid, String money) {
        DingDanInterfaces<OrderBeans> dingdan = new DingDanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(chongzhi_success);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(chongzhi_fail);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);

                    }
                });
        dingdan.chongZhi(uid,money);
    }

    @Override
    public void yueZhiFu(String uid, String pay_code) {
        DingDanInterfaces<OrderBeans> dingdan = new DingDanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(yue_success);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(yue_fail);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);

                    }
                });
        dingdan.yueZhiFu(uid,pay_code);
    }

    @Override
    public void quxiaoZhifu(String uid, String id) {
        DingDanInterfaces<OrderBeans> dingdan = new DingDanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(quxiao_success);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(quxiao_fail);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);

                    }
                });
        dingdan.quxiaoZhifu(uid,id);
    }

    @Override
    public void deleteZhangHao(String uid, String id) {
        DingDanInterfaces<OrderBeans> dingdan = new DingDanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(delete_zhanghao_success);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(delete_zhanghao_fail);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);

                    }
                });
        dingdan.deleteZhangHao(uid,id);
    }

    @Override
    public void cardLeiXing(String bank_no) {
        DingDanInterfaces<OrderBeans> dingdan = new DingDanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(card_type_success);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(card_type_fail);
                        DingDanPresenter.this.setChanged();
                        DingDanPresenter.this.notifyObservers(result);

                    }
                });
        dingdan.cardLeiXing(bank_no);
    }
}
